<?php
defined("_ALLOW") or die ("Access denied");
$task = $_GET['task'];
include_once("class/ccontent.php");
include_once("class/ccategory.php");
global $objcategory;
global $objcontent;
$urlpaging = "";
$urlpaging  = "index.php?module=com_content&task=blogcategory";
if ($task=="blogcategory") {
	$catid = $_GET['id'];
	$urlpaging .= "&id=" . $catid;
}
else if ($task=="view") {
	$id =$_GET['id'];
	$objcontent = $objcontent->Doc($id);
	$catid = $objcontent->catid;
}
else {
	$urlpaging  = "index.php?module=com_content&task=blogsection";
	$sid = $_GET['id'];
	$urlpaging .= "&id=" . $sid;
}
if (isset($_GET['Itemid'])) {
	$itemid = $_GET['Itemid'];
	$urlpaging .= "&Itemid=$itemid";
}
?>
<script language="javascript">
var url = "<?php echo $urlpaging; ?>";
function GotoPage (page) {
	var urltopage;
	urltopage = url + "&curPage=" + page;
	location.href = urltopage;
//	Ajax_Goto(url);
}
</script>
<?php
global $maxwidthimage;
global $cfg_scale_width;
switch ($task) {
	case "view":
		global $cfg_full_width;
		$maxwidthimage = $cfg_full_width;
?>
<div >
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td>
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
									<tr>
										<td style="background-image:url(images/search1.jpg); background-repeat:no-repeat" width="16" height="35"></td>
										<td style="background-image:url(images/search2.jpg); background-repeat:repeat-x; " class="title_category"><?php
	$objcategory = $objcategory->Doc($catid);
	echo $objcategory->Get_Title();
?></td>
										<td style="background-image:url(images/search3.jpg); background-repeat:no-repeat" width="15" height="35"></td>
									</tr>
								</table>
		</td>
	</tr>
	<tr>
		<td height="30" valign="top" style="background-image:url(images/search4.jpg); background-repeat:repeat-y; " class="td_listcontent_tt" >
		<?php echo $objcontent->Out_TheHien($maxwidthimage); ?>
		</td>
	</tr>
	<tr>
		<td style="background-image:url(images/search5.jpg); background-repeat:no-repeat" height="9"></td>
	</tr>
</table>

</div>

<?php
$ttime = $objcontent->ttime;
global $lang;
global $totalRows;
$maxRows = 100;
$idcontent = $objcontent->id;
/////////Các tin đã đưa//////////////////
$strwhere = "catid=$catid AND time < '$ttime' AND id <> $idcontent";
$totalRows = $objcontent->CountFill($strwhere);
if ($totalRows > 0) {
?>

<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td style="background-image:url(images/search6.jpg); background-repeat:no-repeat" height="9"></td>
	</tr>
	<tr>
		<td height="30" valign="top" style="background-image:url(images/search4.jpg); background-repeat:repeat-y; " class="td_listcontent_tt" >
		<div class="title_list_foot" align="left">
		<?php if ($lang=="vn") echo "Các tin đã đưa"; else echo "Older news"; ?>
		</div>
		<div class="td_listcontent_foot">
  <?php
	$begin = $totalRows - $maxRows;
	if ($begin < 0) $begin = 0;
	$array = $objcontent->Fill($strwhere, $maxRows, $begin);
	include_once("common/paging.php");
	$maxwidthimage = $cfg_scale_width;
	Paging_content_foot($array, 1);
?>
</div>
		</td>
	</tr>
	<tr>
		<td style="background-image:url(images/search5.jpg); background-repeat:no-repeat" height="9"></td>
	</tr>
</table>


<?php
}
////////////Các tin khác/////////////////////////
$strwhere = "catid=$catid AND time >= '$ttime' AND id <> $idcontent";
$totalRows = $objcontent->CountFill($strwhere);
if ($totalRows > 0) {
?>

<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td style="background-image:url(images/search6.jpg); background-repeat:no-repeat" height="9"></td>
	</tr>
	<tr>
		<td height="30" align="right" valign="top" style="background-image:url(images/search4.jpg); background-repeat:repeat-y; " class="td_listcontent_tt" class="td_bodycontent">
		<div class="title_list_foot" align="left">
		<?php if ($lang=="vn") echo "Các tin khác"; else echo "Later news"; ?>
		</div>
		<div class="td_listcontent_foot">
  <?php
	$begin = $totalRows - $maxRows;
	if ($begin < 0) $begin = 0;
	$array = $objcontent->Fill($strwhere, $maxRows, $begin);
	include_once("common/paging.php");
	$maxwidthimage = $cfg_scale_width;
	Paging_content_foot($array, 1);
?>
</div>
		</td>
	</tr>
	<tr>
		<td style="background-image:url(images/search5.jpg); background-repeat:no-repeat" height="9"></td>
	</tr>
</table>


<?php
}
		break;
	case "blogcategory":
?>
<div >
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr>
		<td>
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
									<tr>
										<td style="background-image:url(images/search1.jpg); background-repeat:no-repeat" width="16" height="35"></td>
										<td style="background-image:url(images/search2.jpg); background-repeat:repeat-x; " class="title_category"><?php
	$objcategory = $objcategory->Doc($catid);
	echo $objcategory->Get_Title();
?></td>
										<td style="background-image:url(images/search3.jpg); background-repeat:no-repeat" width="15" height="35"></td>
									</tr>
								</table>
		</td>
	</tr>
	<tr>
		<td height="30" align="right" valign="top" style="background-image:url(images/search4.jpg); background-repeat:repeat-y; " class="td_listcontent_tt">
		<?php
	global $totalRows;
  	$totalRows = $objcontent->CountFill("catid=" . $catid);
	if ($totalRows > 0) {
		$pagingcolumns = 1;
		global $maxRows;
		$maxRows = 100;
		global $maxPages;
		$maxPages = 5;
		include_once("common/paging.php");
		global $curPage;
		$paging = Paging_GetPaging();
		$beginrow = ($curPage-1) * $maxRows;
		$array = $objcontent->Doc_danh_sach($catid, $maxRows, $beginrow);
		$maxwidthimage = $cfg_scale_width;
		Paging_List_Content_TT ($array, $pagingcolumns);
		echo $paging;
	}
  ?>
		</td>
	</tr>
	<tr>
		<td style="background-image:url(images/search5.jpg); background-repeat:no-repeat" height="9"></td>
	</tr>
</table>

</div>

<?php
		break;
	case "blogsection":
?>
<div class="title_category">
<?php
	include_once("class/csection.php");
	global $objsection;
	$objsection = $objsection->Doc($sid);
	$objsection->Out_Title_Link();
?>
</div>
<div class="td_listcontent_tt">
  <?php
	global $totalRows;
  	$totalRows = $objcontent->CountFill("sid=" . $sid);
	if ($totalRows > 0) {
		$pagingcolumns = 1;
		global $maxRows;
		$maxRows = 10;
		global $maxPages;
		$maxPages = 5;
		include_once("common/paging.php");
		global $curPage;
		$paging = Paging_GetPaging();
		$beginrow = ($curPage-1) * $maxRows;
		$array = $objcontent->Fill("sid=" . $sid, $maxRows, $beginrow);
		$maxwidthimage = $cfg_scale_width;
		Paging_List_Content_TT ($array, $pagingcolumns);
		echo $paging;
	}
  ?>
</div>
<?php
	default:
		die("Address Fail");
}
?>